package ro.prjmanager.core.list;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: vio
 * Date: 29.03.2010
 * Time: 22:05:15
 * To change this template use File | Settings | File Templates.
 */
public class Json {
     private static final Log log= LogFactoryImpl.getLog(Json.class);
    public static synchronized Map<String,String> fromJson(String jsonString){
        Map<String,String> ret=new HashMap<String, String>();
        try {
            JSONObject jsonObject=new JSONObject(jsonString);
            Iterator it=jsonObject.keys();
            while(it.hasNext()){
                String key= (String) it.next();
                ret.put(key, (String) jsonObject.get(key));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return ret;
    }
    public static void main(String[] args) {

        try {
            JSONObject jsonObject=new JSONObject("{name:onChange , fmk :onBlur}");
            Iterator it=jsonObject.keys();
            while(it.hasNext()){
                String key= (String) it.next();
                System.out.println(key+":"+jsonObject.get(key));


            }

        } catch (JSONException e) {
            log.error(e);
        }
    }
}
